//
//  GetCrashViewController.m
//  Cat
//
//  Created by lushitong on 2019/1/9.
//  Copyright © 2019年 lushitong. All rights reserved.
//

#import "GetCrashViewController.h"
#import "BindViewController.h"
#import "HttpUserManager.h"

@interface GetCrashViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) UILabel *topInfoLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *carshLabel;
@property (nonatomic, strong) UILabel *payNumberLabel;
@property (nonatomic, strong) UIButton *fixButton;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *nameDetailsLabel;
@property (nonatomic, strong) UILabel *tixianLabel;
@property (nonatomic, strong) UITextField *keyixianTextFiled;
@property (nonatomic, strong) UILabel *infoTextLabel;
@property (nonatomic, strong) UIButton *tijiaoButton;

@property (nonatomic, strong) UIView *line1;
@property (nonatomic, strong) UIView *line2;
@property (nonatomic, strong) UIView *line3;
@end

@implementation GetCrashViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	self.topTitleView.bottomLineView.backgroundColor = [UIColor whiteColor];
	self.view.backgroundColor = [UIColor whiteColor];
	self.view.userInteractionEnabled = YES;
    [self.topTitleView setDetailDic:@{Nav_Title:@"提现"}.mutableCopy];
	[self loadAllSubViews];
	self.moneyLabel.text = [NSString stringWithFormat:@"￥%@",self.balanceNumber ? self.balanceNumber : @"0"];
	self.payNumberLabel.text = self.alipayaccount.length > 0 ? self.alipayaccount : @"暂无";
	self.nameDetailsLabel.text = self.alipayName;
	self.keyixianTextFiled.placeholder = [NSString stringWithFormat:@"可提现￥%@",self.balanceNumber ? self.balanceNumber : @"0"];
}


- (void)loadAllSubViews {
	[self.view addSubviews:@[self.topInfoLabel,self.moneyLabel,self.carshLabel,self.payNumberLabel,self.fixButton,self.nameLabel,self.nameDetailsLabel,
							 self.tixianLabel,self.keyixianTextFiled,self.infoTextLabel,self.tijiaoButton,self.line1,self.line2,self.line3]];
	
	[self.topInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.view.mas_centerX);
		make.top.equalTo(self.topTitleView.mas_bottom).offset(kQKFitModuleDecimal(10.0));
	}];
	
	[self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.topInfoLabel.mas_bottom).offset(kQKFitModuleDecimal(1.0));
		make.centerX.equalTo(self.topInfoLabel.mas_centerX);
	}];
	
	[self.carshLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.view.mas_left).offset(kQKFitModuleDecimal(28.0));
		make.top.equalTo(self.moneyLabel.mas_bottom).offset(kQKFitModuleDecimal(28.0));
	}];
	
	[self.payNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.carshLabel.mas_right).offset(kQKFitModuleDecimal(21));
		make.centerY.equalTo(self.carshLabel.mas_centerY);
	}];
	
	[self.fixButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(48), kQKFitModuleDecimal(28.0)));
		make.right.equalTo(self.view.mas_right).offset(-kQKFitModuleDecimal(27.0));
		make.centerY.equalTo(self.carshLabel.mas_centerY).offset(-kQKFitModuleDecimal(1.0));
	}];
	
	[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.carshLabel.mas_left);
		make.top.equalTo(self.carshLabel.mas_bottom).offset(kQKFitModuleDecimal(42));
	}];
	
	[self.nameDetailsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.nameLabel.mas_centerY);
		make.left.equalTo(self.payNumberLabel.mas_left);
	}];
	
	[self.tixianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nameLabel.mas_left);
		make.top.equalTo(self.nameLabel.mas_bottom).offset(kQKFitModuleDecimal(42.0));
	}];
	
	[self.keyixianTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nameDetailsLabel.mas_left);
		make.centerY.equalTo(self.tixianLabel.mas_centerY);
        make.width.equalTo(@(ScreenWidth - kQKFitModuleDecimal(100)));
	}];
	
	[self.infoTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.tixianLabel.mas_left);
		make.top.equalTo(self.tixianLabel.mas_bottom).offset(kQKFitModuleDecimal(19));
	}];
	
	[self.tijiaoButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(321), kQKFitModuleDecimal(40.0)));
		make.centerX.equalTo(self.view.mas_centerX);
		make.top.equalTo(self.infoTextLabel.mas_bottom).offset(kQKFitModuleDecimal(32));
	}];
	
	[self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.view.mas_left).offset(kQKFitModuleDecimal(28.0));
		make.right.equalTo(self.view.mas_right).offset(-kQKFitModuleDecimal(28.0));
		make.top.equalTo(self.carshLabel.mas_bottom).offset(5);
		make.height.equalTo(kQKFitModuleDecimal(1.0));
	}];
	
	[self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.view.mas_left).offset(kQKFitModuleDecimal(28.0));
		make.right.equalTo(self.view.mas_right).offset(-kQKFitModuleDecimal(28.0));
		make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
		make.height.equalTo(kQKFitModuleDecimal(1.0));
	}];
	
	[self.line3 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.view.mas_left).offset(kQKFitModuleDecimal(28.0));
		make.right.equalTo(self.view.mas_right).offset(-kQKFitModuleDecimal(28.0));
		make.top.equalTo(self.keyixianTextFiled.mas_bottom).offset(5);
		make.height.equalTo(kQKFitModuleDecimal(1.0));
	}];
}

- (void)fixButtonAction {
	BindViewController *bindVC = [[BindViewController alloc] init];
	[self.navigationController pushViewController:bindVC animated:YES];
}

- (void)tijaoshenqing {
    if ([self.keyixianTextFiled.text doubleValue] <= 0 || self.keyixianTextFiled.text.doubleValue > self.balanceNumber.doubleValue) {
        [FLProgressHUD showError:@"请输入正确金额"];
        return;
    }
    NSNumber *monet = @([self.keyixianTextFiled.text doubleValue]);
    [HttpUserManager balanceamount:monet PutSuccuss:^(NSDictionary *dict) {
        [self.navigationController popViewControllerAnimated:YES];
        [FLProgressHUD showSuccess:@"申请成功"];
    } failure:^(NSInteger code, NSString *message) {
        [FLProgressHUD showError:message];
    }];
}

#pragma mark----- lazy init -----

- (UILabel *)topInfoLabel {
	if (!_topInfoLabel) {
		_topInfoLabel = [UILabel labelWithText:@"可提现金额" font:[UIFont systemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _topInfoLabel;
}

- (UILabel *)moneyLabel {
	if (!_moneyLabel) {
		_moneyLabel = [UILabel labelWithText:@"￥20.00" font:[UIFont systemFontOfSize:kQKFitFont(36)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _moneyLabel;
}

- (UILabel *)carshLabel {
	if (!_carshLabel) {
		_carshLabel = [UILabel labelWithText:@"可提现支付宝" font:[UIFont boldSystemFontOfSize:kQKFitFont(16)] textColor:COLOR_WITH_HEX(0x4C4947)];
	}
	return _carshLabel;
}

- (UILabel *)payNumberLabel {
	if (!_payNumberLabel) {
		_payNumberLabel = [UILabel labelWithText:@"Tom@qq.com" font:[UIFont systemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0x756D68)];
	}
	return _payNumberLabel;
}

- (UIButton *)fixButton {
	if (!_fixButton) {
		_fixButton = [UIButton buttonWithTitle:@"修改" color:[UIColor whiteColor] font:[UIFont systemFontOfSize:12] cornerRadius:kQKFitModuleDecimal(6.0)];
		[_fixButton setBackgroundColor:COLOR_WITH_HEX(0xFFC236)];
		[_fixButton addTarget:self action:@selector(fixButtonAction) forControlEvents:UIControlEventTouchUpInside];
	}
	return _fixButton;
}

- (UILabel *)nameLabel {
	if (!_nameLabel) {
		_nameLabel = [UILabel labelWithText:@"姓名" font:[UIFont boldSystemFontOfSize:kQKFitFont(16)] textColor:COLOR_WITH_HEX(0x4C4947)];
	}
	return _nameLabel;
}

- (UILabel *)nameDetailsLabel {
	if (!_nameDetailsLabel) {
		_nameDetailsLabel = [UILabel labelWithText:@"钟**" font:[UIFont systemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0x4C4947)];
	}
	return _nameDetailsLabel;
}

- (UILabel *)tixianLabel {
	if (!_tixianLabel) {
		_tixianLabel = [UILabel labelWithText:@"提现金额" font:[UIFont boldSystemFontOfSize:kQKFitFont(16)] textColor:COLOR_WITH_HEX(0x4C4947)];
	}
	return _tixianLabel;
}

- (UITextField *)keyixianTextFiled {
	if (!_keyixianTextFiled) {
        _keyixianTextFiled = [[UITextField alloc] init];
        _keyixianTextFiled.rightViewMode = UITextFieldViewModeWhileEditing;
        _keyixianTextFiled.keyboardType = UIKeyboardTypeDecimalPad;
        _keyixianTextFiled.font = [UIFont systemFontOfSize:kQKFitModule(14)];
        _keyixianTextFiled.textColor = [UIColor qkC2Color];
        _keyixianTextFiled.tintColor = COLOR_WITH_HEX(0x365EED);
        _keyixianTextFiled.delegate = self;
        _keyixianTextFiled.placeholder = @"请输入提现金额";
	}
	return _keyixianTextFiled;
}

- (UILabel *)infoTextLabel {
	if (!_infoTextLabel) {
		_infoTextLabel = [UILabel labelWithText:@"每月25号可提现上一月佣金" font:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _infoTextLabel;
}

- (UIButton *)tijiaoButton {
	if (!_tijiaoButton) {
		_tijiaoButton = [UIButton buttonWithTitle:@"提交申请" color:COLOR_WITH_HEX(0x4C4947) font:[UIFont boldSystemFontOfSize:kQKFitFont(16)] cornerRadius:kQKFitModuleDecimal(6.0)];
		[_tijiaoButton setBackgroundColor:COLOR_WITH_HEX(0xFFC236)];
		[_tijiaoButton addTarget:self action:@selector(tijaoshenqing) forControlEvents:UIControlEventTouchUpInside];
	}
	return _tijiaoButton;
}

- (UIView *)line1 {
	if (!_line1) {
		_line1 = [[UIView alloc] init];
		_line1.backgroundColor = COLOR_WITH_HEX(0xEEEBEB);
	}
	return _line1;
}

- (UIView *)line2 {
	if (!_line2) {
		_line2 = [[UIView alloc] init];
		_line2.backgroundColor = COLOR_WITH_HEX(0xEEEBEB);
	}
	return _line2;
}

- (UIView *)line3 {
	if (!_line3) {
		_line3 = [[UIView alloc] init];
		_line3.backgroundColor = COLOR_WITH_HEX(0xEEEBEB);
	}
	return _line3;
}

@end
